<?php

define('NOCHARSET', true);
require_once 'include/common.inc.php';

$authnum = rand(1000, 9999);
dsetcookie('authnum', $authnum);

//生成验证码图片
Header("Content-type: image/PNG");
$im = imagecreate(58, 20);
$white = ImageColorAllocate($im, 0, 0, 0);
$white = ImageColorAllocate($im, 255, 255, 255);
$gray = ImageColorAllocate($im, 200, 200, 200);
imagefill($im, 68, 30, $gray);

//将四位整数验证码绘入图片
imagestring($im, 5, 10, 2, $authnum, $white);

for ($i = 0; $i < 100; $i++) {   //加入干扰象素
    imagesetpixel($im, rand() % 70, rand() % 30, $white);
}

ImagePNG($im);
ImageDestroy($im);
?>
